package com.itheima.wemedia.controller;

import com.itheima.common.pojo.Result;
import com.itheima.wemedia.pojo.WmUser;
import com.itheima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wmuser")
public class LoginController {

    @Autowired
    private WmUserService wmUserService;

    /**
     * 用户登录
     */
    @PostMapping(value = "/login")
    public Result login(@RequestBody WmUser wmUser){
        String token = wmUserService.login(wmUser);
        if (StringUtils.isEmpty(token)){
            return Result.errorMessage("服务器繁忙");
        }

        return Result.ok(token);
    }

}
